package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menu/")
public class SysMenuController {
    @Autowired
    private SysMenusService sysMenusService;

    @GetMapping("treeNodes")
    public JsonResult doFindMenuTreeNodes(){
        return new JsonResult(sysMenusService.findMenuTreeNodes());
    }
    @GetMapping
    public JsonResult doFindMenus(){
        return new JsonResult(sysMenusService.findMenus());
    }
    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id)  {
        return new JsonResult(sysMenusService.findById(id));

    }
    @PostMapping
    public JsonResult doSaveMenu(@RequestBody SysMenu sysMenu){
        sysMenusService.saveMenu(sysMenu);
        return new JsonResult("OK");
    }
    @PutMapping()
    public JsonResult doUpdateMenu(@RequestBody SysMenu sysMenu){
        sysMenusService.updateMenu(sysMenu);
        return new JsonResult("update ok");
    }
}
